package gestion.camping.vue;

import gestion.camping.controleur.HomeController;
import gestion.camping.utils.MessagesUtil;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import java.awt.GridBagConstraints;

public class ViewHome extends JFrame implements ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2106601198593427861L;
	
	private HomeController controller;
	
	private JPanel contentPane;
	private JMenuItem btnMenuPersonne;	
	private JMenuItem btnMenuReservation;
	private JMenuItem btnMenuEmplacement;
	private JMenuItem btnMenuSaison;
	private JMenuItem btnMenuFraisReservation;
	private JMenuItem btnMenuTarif;
	private JMenuItem btnMenuAccueil;
	private JButton btnFormulaireResa;

	/**
	 * Create the frame.
	 */
	public ViewHome(HomeController controller) {
		
		this.setController(controller);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(0, 0, 1200, 750);
		getContentPane().setLayout(null);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		btnMenuAccueil = new JMenuItem(MessagesUtil.formatMessage("menu.accueil.title"));
		btnMenuAccueil.addActionListener(this);
		menuBar.add(btnMenuAccueil);
		
		btnMenuPersonne = new JMenuItem(MessagesUtil.formatMessage("menu.personne.title"));
		btnMenuPersonne.addActionListener(this);
		menuBar.add(btnMenuPersonne);
				
		btnMenuReservation = new JMenuItem(MessagesUtil.formatMessage("menu.reservation.title"));
		btnMenuReservation.addActionListener(this);
		menuBar.add(btnMenuReservation);
		
		btnMenuEmplacement = new JMenuItem(MessagesUtil.formatMessage("menu.emplacement.title"));
		btnMenuEmplacement.addActionListener(this);
		menuBar.add(btnMenuEmplacement);
		
		btnMenuSaison = new JMenuItem(MessagesUtil.formatMessage("menu.saison.title"));
		btnMenuSaison.addActionListener(this);
		menuBar.add(btnMenuSaison);
		
		btnMenuFraisReservation = new JMenuItem(MessagesUtil.formatMessage("menu.fraisReservation.title"));
		btnMenuFraisReservation.addActionListener(this);
		menuBar.add(btnMenuFraisReservation);
		
		btnMenuTarif = new JMenuItem(MessagesUtil.formatMessage("menu.tarif.title"));
		btnMenuTarif.addActionListener(this);
		menuBar.add(btnMenuTarif);
		
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		GridBagLayout gbl_contentPane = new GridBagLayout();
		gbl_contentPane.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
		gbl_contentPane.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gbl_contentPane.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		contentPane.setLayout(gbl_contentPane);
		
		btnFormulaireResa = new JButton(MessagesUtil.formatMessage("accueil.btn.formReservation"));
		btnFormulaireResa.addActionListener(this);
		GridBagConstraints gbc_btnFormulaireResa = new GridBagConstraints();
		gbc_btnFormulaireResa.gridx = 18;
		gbc_btnFormulaireResa.gridy = 6;
		contentPane.add(btnFormulaireResa, gbc_btnFormulaireResa);
		
	}


	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == this.btnMenuPersonne){
			controller.getControllerPersonne();
		}else if(e.getSource() == this.btnMenuReservation){
			controller.getControllerReservation();
		}else if(e.getSource() == this.btnMenuEmplacement){
			controller.getControllerEmplacement();
		}else if(e.getSource() == this.btnMenuSaison){
			controller.getControllerSaison();
		}else if(e.getSource() == this.btnMenuFraisReservation){
			controller.getControllerFraisReservation();
		}else if(e.getSource() == this.btnMenuTarif){
			controller.getControllerTarif();
		}else if(e.getSource() == this.btnMenuAccueil){
			controller.getControllerAccueil();
		}else if(e.getSource() == this.btnFormulaireResa){
			controller.getFormulaireReservation();
		}
	}


	public HomeController getController() {
		return controller;
	}


	public void setController(HomeController controller) {
		this.controller = controller;
	}
}
